package com.mapper;


import com.pojo.News;
import com.pojo.News1;
import com.pojo.NewsList;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Component;

import java.util.List;

@Mapper
@Component
public interface NewsMapper {

    /*
     * @Author 陆微腾
     * @Description 分页查询
     * @Date: 2020/4/17
     * @MethodName: findAll
     * @Param []
     * @return java.util.List<com.pojo.News>
     **/
    @Select("select * from news")
    List<News> findAll();


//    select  type,title,pubtime,contxturl from news 查找部分信息

    @Insert("insert into news(newsnum,title,type,pubtime,newsfrom,contxt,contxturl) values(#{newsnum},#{title},#{type},#{pubtime},#{newsfrom},#{contxt},#{contxturl})")
    void insert(News1 news);


    @Select("SELECT * FROM news WHERE  TYPE = #{type} GROUP BY addtime DESC LIMIT 1")
    News findOne(int type);

    @Results(value = {
            @Result(property = "title", column = "title"),
            @Result(property = "url", column = "contxturl"),
            @Result(property = "time", column = "pubtime")
    })
    @Select("SELECT title,contxturl,pubtime FROM news WHERE TYPE= #{type} ORDER BY ADDTIME DESC LIMIT 30")
    List<NewsList> findByTypeTop30(int type);
}
